package org.example;

import com.google.genai.Client;
import com.google.genai.types.Content;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Part;
import com.google.common.collect.ImmutableList;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import com.google.auth.oauth2.GoogleCredentials;



public class Main {
    private static final String SERVICE_ACCOUNT_KEY_PATH = "D:\\jrl\\pwd\\google\\gcpproject-25sep08-fc7b270f208b.json";

    public static void main(String[] args) {
        GoogleCredentials credentials = null; // 初始化为null


        try (FileInputStream serviceAccountStream = new FileInputStream(SERVICE_ACCOUNT_KEY_PATH)) {
          
            List<String> scopes = Collections.singletonList("https://www.googleapis.com/auth/cloud-platform");

            credentials = GoogleCredentials.fromStream(serviceAccountStream)
                    .createScoped(scopes);
        } catch (IOException e) {
            System.err.println("Error loading service account key: " + e.getMessage());
            System.err.println("Please ensure the path is correct and the file exists.");
            e.printStackTrace();
            return; // 无法加载凭据，退出程序
        }

        Client client = Client.builder()
                .project("gcpproject-25sep08")
                .location("global")
                .vertexAI(true)
                .credentials(credentials)
                .build();


        String model = "gemini-2.5-flash-image";
        List<Content> contents = ImmutableList.of(
                Content.builder()
                        .role("user")
                        .parts(ImmutableList.of(
                                Part.fromText("景别:中景\n" +
                                      "视角：极限仰视视角，超低广角镜头，地面视角\n" +
                                      "氛围:有一点微弱的光线，阴影笼罩，阴森恐怖的氛围感觉，背景虚化\n" +
                                      "主体:镜头从男子下巴下方拍摄，男子右手撑在拍卖桌上，身体激动地前倾，右手摁在拍卖卓上，左手拿着一个小型木制拍卖锤，表情高兴兴奋，张嘴激动的说话，画面上方有白色的聚光灯光照，背景是虚化背景。2d动画风格，线条感强，拍卖桌和男子同样宽度。...仰视，地面视角。能看到男子头顶的聚光灯")
                        ))
                        .build()
        );

        GenerateContentConfig config =
                GenerateContentConfig
                        .builder()
                        .responseMimeType("text/plain")
                        //.systemInstruction(
                        //        Content.fromParts(
                        //                Part.fromText("You are a translator who is proficient in multiple languages."),
                        //                Part.fromText("Please help me translate the input content into the corresponding language version according to the set variables. "),
                        //                Part.fromText("Please keep the original sentence wrapping and indentation, keep the sentence smooth and semantically unchanged."),
                        //                Part.fromText("Please strictly return in the following Markdown format without any other instructions."),
                        //                Part.fromText("The target language is Chinese.")
                        //        )
                        //)
                        .build();


        GenerateContentResponse response = client.models.generateContent(model, contents, config);


        System.out.println(response.text());


    }
}